define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    var Controller = {
        index: function () {
            var travel_id = GetQueryString('travel_id');
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'travelmember/index?travel_id='+travel_id,
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'travel_member',
                }
            },
            {
                custom:{'已支付':'success','未支付':'danger','已签到':'success','未签到':'danger'}
            }
            );

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title:'ID', operate:false,},
                        /*{field: 'travel_id', title: __('Travel_id')},*/
                        {field: 'user_name', title: __('Member_id'), operate:false,},
                        {field: 'paid_text', title: __('Paid'), operate:false, formatter: Table.api.formatter.flag, searchList: {'0': '未支付', '1': '已支付','2':'订金已支付'},},
                        {field: 'paid', title: __('Paid'),visible: false, formatter: Table.api.formatter.flag, searchList: {'0': '未支付', '1': '已支付','2':'订金已支付'},},
                        {field: 'paid_fee', title: __('Paid_fee'), operate:false},
                        {field: 'is_checkin', title: __('Is_checkin'), formatter: Table.api.formatter.flag, searchList: {'0': '未签到', '1': '已签到'}},
                        {field: 'check_time', title: __('Check_time'), formatter: Table.api.formatter.datetime, operate:false},
                        {field: 'deposit', title: __('Deposit'), operate:false, operate:false},
                        {field: 'parent_name', title: __('Parentid'), operate:false,},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate:false},
                        /*{field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime},*/
                        /*{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}*/
                       /* {field: 'operate', title: __('Operate'), table: table, 
                            buttons:[{
                                name: 'remind', 
                                text: '支付尾款提醒', 
                                classname: 'btn btn-xs btn-info btn-fields btn-ajax', 
                                icon: 'fa fa-list', 
                                url: 'travelmember/remind?tmid={ids}'
                            }],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate
                        }*/
                        {field: 'operate', title: __('Operate'), table: table,
                             events: Table.api.events.operate,
                             buttons: [
                                {
                                    name: 'remind',
                                    text: '支付尾款提醒',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-info btn-fields btn-ajax', 
                                    url: 'travelmember/remind?tmid={ids}'
                                },
                                {
                                    name: 'detail',
                                    text: '其他',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-info btn-fields btn-dialog', 
                                    url: 'travelmember/detail?tmid={ids}'
                                }],
                                formatter: Table.api.formatter.operate,
                             formatter: function (value, row, index)
                             {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                if (row.type == 0)
                                    $(table).data("operate-remind", false);
                                if (row.type == 1)
                                    $(table).data("operate-detail", false);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                             }
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});